package com.crazyhat.crazyhat.dto;

import java.io.IOException;
import java.util.UUID;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import com.crazyhat.crazyhat.attribute.PostPublicScopeEnum;
import org.springframework.web.multipart.MultipartFile;

import com.crazyhat.crazyhat.anno.ClubCategoryAnno;
import com.crazyhat.crazyhat.anno.SensitiveWordAnno;
import com.crazyhat.crazyhat.utils.ObsUtil;

import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateClubDTO {

        private String imageDirectory = "img/";

        @Size(max = 20)
        @SensitiveWordAnno
        private String clubName;

        /**
         * 社团介绍文字部分
         */
        @SensitiveWordAnno
        @NotEmpty
        private String descriptionContent;

        @ClubCategoryAnno
        @NotNull
        private String category;

        @SensitiveWordAnno
        @NotEmpty
        private String requirements;

        /**
         * logo图片
         */
        private MultipartFile logoPicture;

        private PostPublicScopeEnum postPublicScopeEnum;

        public String uploadPicture() throws IOException {

                String originalFileName = this.logoPicture.getOriginalFilename();

                /**
                 * 文件名替换为uuid，并添加父目录名
                 */
                String savedfileName = imageDirectory + UUID.randomUUID().toString()
                                + originalFileName.substring(originalFileName.lastIndexOf("."));
                return ObsUtil.uploadFile(savedfileName, logoPicture.getInputStream());
        }

}
